package job.antispam.graph_building.domain;

import java.io.IOException;

import mapred.Job;
import mapred.config.CombineConfig;
import mapred.config.Compress;
import mapred.config.InputConfig;
import mapred.config.JobConfig;
import mapred.config.MapConfig;
import mapred.config.OutputConfig;
import mapred.config.ReduceConfig;
import mapred.example.FeatureMap_Sum_Reducer;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.KeyValueTextInputFormat;
import org.apache.hadoop.mapred.RunningJob;
import org.apache.hadoop.mapred.TextOutputFormat;

public class DomainGraphGenerator extends Job {

    public DomainGraphGenerator(String... settings) throws IOException {
        super("Domain Link Graph Generator", settings);
    }

    @Override
    protected CombineConfig getCombineConfig() {
        return CombineConfig.newInstance(FeatureMap_Sum_Reducer.class);
    }

    @Override
    protected InputConfig getInputConfig(FileSystem fs) throws IOException {
        return InputConfig.newInstance(KeyValueTextInputFormat.class, this
                .getUserSetting("-input"));
    }

    @Override
    protected MapConfig getMapConfig() {
        return MapConfig.newInstance(DomainGraphGenerator_Mapper.class,
                Text.class, Text.class);
    }

    @Override
    protected OutputConfig getOutputConfig(FileSystem fs) throws IOException {
        return OutputConfig.newInstance(TextOutputFormat.class, Text.class,
                Text.class, this.getUserSetting("-output"), Compress.GZIP);
    }

    @Override
    protected ReduceConfig getReduceConfig() {
        return ReduceConfig.newInstance(FeatureMap_Sum_Reducer.class, 50);
    }

    @Override
    protected void setUp(JobConfig conf, FileSystem fs) throws IOException {
        conf.set("delim", "#");
    }

    @Override
    protected void tearDown(JobConfig conf, FileSystem fs, RunningJob job)
            throws IOException {
    }

    public static void main(String[] args) throws Exception {
        // Job.buildXML(DomainGraphGenerator.class);

        new DomainGraphGenerator(args).submit();
    }

}
